$(document).ready(function() 
{ 
     $(".tablesorter").tablesorter(); 
       //When page loads...
     $(".tab_content").hide(); //Hide all content
     $("ul.tabs li:first").addClass("active").show(); //Activate first tab
     $(".tab_content:first").show(); //Show first tab content

            //On Click Event
     $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
     });
     $(".delete").click(function(e){
        var href = this.href;
        e.preventDefault();
        $("#deleteDialog").dialog({
            title: 'benlytourist.com.vn',
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                'Xóa': function(){
                    window.location=href;
                    $(this).dialog('close');
                },
                'Không xóa': function(){
                    $(this).dialog('close');
                }
            }
        });
    });
     $(".browse").click(function(){
	   var finder = new CKFinder();
	   finder.basePath = '../../upload/images';	// The path for the installation of CKFinder (default = "/ckfinder/").
	   finder.selectActionFunction = function(url){
               var value = $(".browse").val();
                   if(value == "") {
                        $(".browse").val(url);
                   }else{
                       $(".browse").val(value+"," + url);
                   }
	   };
	   finder.popup(); 
   });
   
   $("#add_new_cat").click(function(){
       var text = $("select#cats  option:selected").text();
       var value = $("select#cats  option:selected").val();
       if($("#addcats div#cat_item_"+value).length){
            alert("Đã add danh mục "+text+" này rồi!!!");
       }  
       else{
           $("#addcats").append("<div class='cat_item' id='cat_item_"+value+"'><input type='hidden' name='cats_item[]' value='"+value+"'><a href ='#' class='remove_cat'>"+text+"</a></div>");
           remove();
       }
   });
   remove();
  
});
	
function remove(){
   $("a.remove_cat").click(function(){
                $(this).parent().remove();
 });
}